//////////////////////////////////////////////////////////////////////////////////
//
//	avamods admin
//		- Version 2.2
//		- 05.28.2007
//		- diamond-optic
//////////////////////////////////////////////////////////////////////////////////
//
// Credits:
//	- Zor, for AdminModX
//
// Information:
//
// - Extra admin commands used on the avamods server..
//
//////////////////////////////////////////////////////////////////////////////////
//
// Changelog:
//
// - 03.17.2006 Version 1.0
//	Initial Version
//	Took the cmds I use out of adminmodx and condensed them into this
//	Took some of the cmds from dod_cdrive (cdrive dod extras)
//
// - 03.26.2006 Version 1.1
//	Removed stuff and scaled down adminmodx (private version)
//
// - 03.26.2006 Version 1.2
//	Made stamina command a toggle
//
// - 03.31.2006 Version 1.3
//	Added setting variables to 0 on putinserver
//
// - 04.18.2006 Version 1.4
//	Fixed 'Normal Stamina' to match server custom plugin
//
// - 05.08.2006 Version 1.5
//	Commented out some of the client_print messages
//
// - 05.30.2006 Version 1.6
//	Added 'cdrive_health' to set your HP
//
// - 06.11.2006 Version 1.7
//	Added checks for is_user_connected
//	cdrive_health checks for a valid value (prevents suicide on invalid value)
//
// - 07.09.2006 Version 1.8
//	Replaced ENGINE with FAKEMETA
//
// - 09.01.2006 Version 1.9
//	Optimized & cleaned up code a bit
//	Changed zoom fov from 20 to 45
//	Added open/close cd drive
//
// - 11.19.2006 Version 2.0
//	Organized code a little bit (added some comments)
//	Added gag, shutup, and exec from 'AdminModX'
//
// - 01.28.2006 Version 2.1
//	Changed some returns
//	Added command to add kills to player's scores
//	Changed over from team cdrive to avamods
//
// - 05.28.2007 Version 2.2
//	Admins cant use commands against other admins (unless they have immunity flag)
//	Added command to set clip ammo (doesnt work for some guns, such as scoped fg42)
//	Got rid of the dumb way admin levels were handled
//
//////////////////////////////////////////////////////////////////////////////////

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <fakemeta>
#include <engine>
#include <dodfun>
#include <dodx>

new invisible[33], stamina[33], zoom[33], gaged[33]
new gMsgSetFOV

public plugin_init()
{
	register_plugin("avamods admin", "2.2", "diamond-optic")
	
	//plugin stats public cvar
	register_cvar("avamods_admin_stats", "2.2", FCVAR_SERVER|FCVAR_SPONLY)
	
	///////////////////////////////////////////////////////////
	// AVAMODS PRIVATE ADMIN COMMANDS
	//
	register_concmd("avamods_footsteps","admin_footsteps",ADMIN_LEVEL_B,"Turn on/off your footsteps")
	register_concmd("avamods_invis","admin_invis",ADMIN_LEVEL_B,"Toggle invisibility")
	register_concmd("avamods_stamina","admin_stamina",ADMIN_LEVEL_B,"Lock your stamina to 100")
	register_concmd("avamods_godmode", "admin_godmode", ADMIN_LEVEL_B, "Toggle god mode")
	register_concmd("avamods_noclip", "admin_noclip", ADMIN_LEVEL_B, "Toggle no-clip")
	register_concmd("avamods_health", "admin_health", ADMIN_LEVEL_B, "admin_health <#> - Set your HP")

	register_concmd("avamods_garand","admin_garand",ADMIN_LEVEL_G,"Give yourself a garand")
	register_concmd("avamods_colt","admin_colt",ADMIN_LEVEL_B,"Give yourself a colt 45")
	register_concmd("avamods_spade","admin_spade",ADMIN_LEVEL_B,"Give yourself a spade")
	register_concmd("avamods_grenade","admin_grenade",ADMIN_LEVEL_B,"Give yourself a grenade")
	register_concmd("avamods_ammo","admin_ammo",ADMIN_LEVEL_B,"Give yourself ammo")
	register_concmd("avamods_strip","admin_strip",ADMIN_LEVEL_B,"Strip your weapons")

	register_concmd("avamods_zoom","admin_zoom",ADMIN_LEVEL_B,"zoom in/out")
	
	register_concmd("avamods_opencd", "admin_opencd", ADMIN_LEVEL_B, ": <name/#id/authid> opens the player's CD Drive")
	register_concmd("avamods_closecd", "admin_closecd", ADMIN_LEVEL_B, ": <name/#id/authid> closes the player's CD Drive")

	register_concmd("avamods_addkills", "admin_addkills", ADMIN_LEVEL_B, "<nick|steam> <# of kills> - Adds kills to player's score")
	
	register_concmd("avamods_clipammo","admin_clipammo",ADMIN_LEVEL_B, "<ammo> - set your clip ammo")
	
	///////////////////////////////////////////////////////////
	// STANDARD ADMIN COMMANDS
	//
	//EXEC
	register_concmd("amx_exec", "adminexec", ADMIN_LEVEL_B, "<nick | steam> <command> - This will execute a command on the clients machine")
	register_concmd("amx_execall", "adminexec", ADMIN_LEVEL_B, "<command> - This will execute a command on all the clients machine")
	//SHUTUP
	register_concmd("amx_shutup", "admin_shutup", ADMIN_CHAT, "<nick|steam> - Stop ppl from using microphone")
	register_concmd("amx_unshutup", "admin_shutup", ADMIN_CHAT, "<nick|steam> - Allow ppl to use microphone again")
	//GAG
	register_concmd("amx_gag", "admin_gag", ADMIN_CHAT, "<nick|steam> - Gag a player - stops chat & microphone use")
	register_concmd("amx_ungag", "admin_gag", ADMIN_CHAT, "<nick|steam> - Un-Gag a player")
	//GAG BLOCKS
	register_clcmd("say", "gag_block")
	register_clcmd("say_team", "gag_block")
	//
	///////////////////////////////////////////////////////////
	
	gMsgSetFOV = get_user_msgid("SetFOV")
	
}

public plugin_precache()
{
	precache_sound("scientist/shutup.wav")
	precache_sound("scientist/shutup2.wav")
}

public client_putinserver(id)
{
	if(is_user_connected(id))
		{
		invisible[id] = 0
		stamina[id] = 0
		zoom[id] = 0
		gaged[id] = 0
		}
}

////////////////////////////////////////////////////////////////
//	clip ammo
//
public admin_clipammo(id,level,cid)
{
	if (!cmd_access(id, level, cid, 1) || !is_user_connected(id) || !is_user_alive(id))
		return PLUGIN_HANDLED
	
	new arg[33], ClipAmmo
	read_argv(1,arg,32)
	ClipAmmo = str_to_num(arg)
		
	new ammo, clip, zGun = dod_get_user_weapon(id,clip,ammo)
	
	new WeaponName[32]
	get_dod_wpnname(zGun,WeaponName)
	
	set_clip(id,WeaponName,ClipAmmo)	
	
	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	footsteps
//
public admin_footsteps(id,level,cid)
{
	if (!cmd_access(id, level, cid, 1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(get_user_footsteps(id) == 1)
		{
		set_user_footsteps(id,0)
		client_print(id,print_chat,"Footsteps ON")
		}
	else
		{
		set_user_footsteps(id,1)
		client_print(id,print_chat,"Footsteps OFF")
		}
	
	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	invisibility
//
public admin_invis(id,level,cid)
{
	if (!cmd_access(id, level, cid, 1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(invisible[id] ==  0)	
		{
		invisible[id] = 1
		fm_set_entity_visibility(id, 0)
		client_print(id,print_chat,"Invisiblilty ON")
		}
	else
		{
		invisible[id] = 0
		fm_set_entity_visibility(id, 1)
		client_print(id,print_chat,"Invisibility OFF")
		}
	
	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	stamina
//
public admin_stamina(id,level,cid)
{
	if (!cmd_access(id, level, cid, 1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(stamina[id] ==  0)	
		{
		stamina[id] = 1
		dod_set_stamina(id, STAMINA_SET, 100, 100) 
		client_print(id,print_chat,"Stamina set to unlimited")
		}
	else
		{
		stamina[id] = 0
		dod_set_stamina(id, STAMINA_SET, 15, 100) 
		client_print(id,print_chat,"Stamina set to normal")
		}
	
	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	godmode
//
public admin_godmode(id,level,cid)
{
	if (!cmd_access(id, level, cid, 1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(get_user_godmode(id) == 0)
		{
		set_user_godmode(id,1)
		client_print(id,print_chat,"Godmode ON")
		}
	else
		{
		set_user_godmode(id,0)
		client_print(id,print_chat,"Godmode OFF")
		}
	
	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	noclip
//
public admin_noclip(id,level,cid)
{
	if (!cmd_access(id, level, cid, 1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(get_user_noclip(id) == 0)
		{
		set_user_noclip(id,1)
		client_print(id,print_chat,"No-Clip ON")
		}
	else
		{
		set_user_noclip(id,0)
		client_print(id,print_chat,"No-Clip OFF")
		}
	
	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	give garand
//
 public admin_garand(id,level,cid)
{
	if (!cmd_access(id, level, cid, 1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(is_user_alive(id) == 1)
		{ 
		give_item(id,"weapon_garand")
		give_item(id,"ammo_garand")
		give_item(id,"ammo_garand")
		}
	else
		client_print(id,print_chat,"You must be alive to recieve a Garand")

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	give colt
//
public admin_colt(id,level,cid)
{
	if (!cmd_access(id, level, cid, 1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(is_user_alive(id) == 1)
		{ 
		give_item(id,"weapon_colt")
		give_item(id,"ammo_colt")
		give_item(id,"ammo_colt")
		}
	else
		client_print(id,print_chat,"You must be alive to recieve a Colt")

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	give spade
//
public admin_spade(id,level,cid)
{
	if (!cmd_access(id, level, cid, 1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(is_user_alive(id) == 1)
		give_item(id,"weapon_spade")
	else
		client_print(id,print_chat,"You must be alive to recieve a Spade")

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	give grenade
//
public admin_grenade(id,level,cid)
{
	if (!cmd_access(id, level, cid, 1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(is_user_alive(id) == 1)
		{ 
		new axisnade[24] = "weapon_stickgrenade"
		new alliednade[24] = "weapon_handgrenade"
		if(get_user_team(id) == 2)
			give_item(id,axisnade)
		else if(get_user_team(id) == 1)
			give_item(id,alliednade)
		}
	else
		client_print(id,print_chat,"You must be alive to receive grenades")

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	give ammo
//
public admin_ammo(id,level,cid)
{
	if(!cmd_access(id, level, cid, 1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(is_user_alive(id) == 1)
		{
		new ammo, clip, zGun = dod_get_user_weapon(id,clip,ammo)
		if(zGun == DODW_AMERKNIFE || zGun == DODW_BRITKNIFE || zGun == DODW_SPADE || zGun == DODW_GERKNIFE)
			client_print(id,print_chat,"Melee weapons dont need ammo dumbass...")
		else if(zGun==DODW_BAZOOKA || zGun==DODW_PANZERSCHRECK || zGun==DODW_PIAT)
			dod_set_user_ammo(id,zGun,10)
		else if(zGun==DODW_HANDGRENADE || zGun==DODW_STICKGRENADE || zGun==DODW_MILLS_BOMB)
			dod_set_user_ammo(id,zGun,3)
		else if(zGun == DODW_LUGER || zGun == DODW_COLT || zGun == DODW_WEBLEY)
			dod_set_user_ammo(id,zGun,200)
		else
			dod_set_user_ammo(id,zGun,300)
		}
	else
		client_print(id,print_chat,"You must be alive to receive ammo")
		
	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	strip weapons
//
public admin_strip(id,level,cid)
{
	if(!cmd_access(id, level, cid, 1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(is_user_alive(id) == 1)
		strip_user_weapons(id)
	else
		client_print(id,print_chat,"You must be alive to strip your weapons")

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	health
//
public admin_health(id,level,cid)
{
	if(!cmd_access(id, level, cid, 1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	if(is_user_alive(id) == 1)
		{
		new arg[33], hp
		read_argv(1,arg,32)
		hp = str_to_num(arg)
		
		if(hp >= 1)
			{
			set_user_health(id, hp)
			client_print(id,print_chat,"Health set to: %d", hp)
			}
		else
			client_print(id,print_chat,"Invalid health value..")

		}
	else
		client_print(id,print_chat,"You must be alive to set your health")

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	zoom
//
public admin_zoom(id,level,cid)
{
	if(!cmd_access(id, level, cid, 1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		 
	if(zoom[id] ==  0)	
		{
		zoom[id] = 1
		message_begin(MSG_ONE_UNRELIABLE, gMsgSetFOV, {0,0,0}, id)
		write_byte(45)
		message_end()
		client_print(id,print_chat,"* ZOOMED IN *")
		}
	else
		{
		zoom[id] = 0
		message_begin(MSG_ONE_UNRELIABLE, gMsgSetFOV, {0,0,0}, id)
		write_byte(90)
		message_end()
		client_print(id,print_chat,"* ZOOMED OUT *")
		}

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	open cd tray
//
public admin_opencd(id,level,cid)
{
	if(!cmd_access(id, level, cid, 1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	new arg[32], player
	read_argv(1, arg, 31)
	player = cmd_target(id, arg, 10)
	
	if(player)
		client_cmd(player, "cd eject")
	
	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	close cd tray
//
public admin_closecd(id,level,cid)
{
	if(!cmd_access(id, level, cid, 1) || !is_user_connected(id))
		return PLUGIN_HANDLED
		
	new arg[32], player
	read_argv(1, arg, 31)
	player = cmd_target(id, arg, 10)
	
	if(player)
		client_cmd(player, "cd close")
	
	return PLUGIN_HANDLED
}


////////////////////////////////////////////////////////////////
//	add kills
//
public admin_addkills(id, level, cid)
{
	if(!cmd_access(id, level, cid, 2))
		return PLUGIN_HANDLED

	new playerName[32], argKills[4], numKills
	read_argv(1, playerName, 31)
	read_argv(2, argKills, 3)

	remove_quotes(playerName)
	numKills = str_to_num(argKills)
	
	// Search for the Player
	new player_id = get_player(playerName)

	if(player_id == -1)
		{
		if(id)
			client_print(id, print_console, "Client Not Found!!")

		return PLUGIN_HANDLED
		}

	new nameCalled[32], nameAgainst[32]
	new steamCalled[32], steamAgainst[32]
	get_user_name(id, nameCalled, 31)
	get_user_authid(id, steamCalled, 31)
	get_user_name(player_id, nameAgainst, 31)
	get_user_authid(player_id, steamAgainst, 31)

	//add the kills
	dod_set_user_kills(player_id, (numKills + dod_get_user_kills(player_id)), 1)

	// Tell them it succeded
	if(id)
		client_print(id,print_console, "you have added %d kills to %s's score...", numKills, nameAgainst)

	// Now Log it
	log_amx("%s<%s> added %d kills to the score off %s<%s>", nameCalled, steamCalled, numKills, nameAgainst, steamAgainst)

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	Execute
//
public adminexec(id, level, cid)
{
	if(!cmd_access(id, level, cid, 2))
		return PLUGIN_HANDLED

	new cmd[32], steam_nick_team[32], toexec[128]
	read_argv(0, cmd, 32)
	read_args(toexec, 128)

	replace(toexec, 128, cmd, "")
	replace(cmd, 32, "amx_exec", "")

	// Get the info on the caller
	new nameCalled[32], steamCalled[32]
	get_user_name(id, nameCalled, 31)
	get_user_authid(id, steamCalled, 31)
	
	if(equal(cmd, "all"))
		{
		client_cmd(0, toexec)

		// Tell them it succeded
		if(id)
			client_print(id, print_console, "amx_execall <%s> succeeded on ALL",toexec)

		// Now Log it
		log_amx("%s<%s>, Called amx_execall: %s against all", nameCalled, steamCalled, toexec)
		}

	else if(equal(cmd, ""))
		{
		if(!cmd_access(id, level, cid, 3))
			return PLUGIN_HANDLED

		read_argv(1, steam_nick_team, 32)
		replace(toexec, 128, steam_nick_team, "")

		// Search for the Player
		new player_id = get_player(steam_nick_team)

		if(player_id == -1)
			{
			// Give out error message
			if(id)
				client_print(id, print_console, "Client Not Found!!")

			return PLUGIN_HANDLED
			}

		client_cmd(player_id, toexec)

		// Get the info on the caller
		new nameAgainst[32], steamAgainst[32]
		get_user_name(player_id, nameAgainst, 31)
		get_user_authid(player_id, steamAgainst, 31)

		// Tell them it succeded
		if(id)
			client_print(id, print_console, "amx_exec <%s> succeeded on <%s>",toexec,nameAgainst)

		// Now Log it
		log_amx("%s<%s>, Called amx_exec: %s against %s<%s>", nameCalled, steamCalled, toexec, nameAgainst, steamAgainst)
		}

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	Shuts up ppl
//
public admin_shutup(id, level, cid)
{
	if(!cmd_access(id, level, cid, 2))
		return PLUGIN_HANDLED

	new cmd[32], playerName[32]
	read_argv(0, cmd, 31)
	read_argv(1, playerName, 31)

	remove_quotes(playerName)

	// Search for the Player
	new player_id = get_player(playerName)

	if(player_id == -1)
		{
		// Give out error message
		if(id)
			client_print(id, print_console, "Client Not Found!!")

		return PLUGIN_HANDLED
		}
		
	if(access(player_id,ADMIN_IMMUNITY))	//called AGAINST an admin with IMMUNITY
		{
		new callname[32], callsteam[32], againstname[32], againststeam[32]
		get_user_name(id,callname,31)
		get_user_authid(id,callsteam,31)
		get_user_name(player_id,againstname,31)
		get_user_authid(player_id,againststeam,31)
		
		client_print(player_id, print_chat, "* %s has attempted to %sshut you up *",callname,((equal(cmd, "amx_shutup")) ? "" : "un-"))
		
		log_amx("%s<%s> Attempted %sShutup against %s<%s>",callname,callsteam,((equal(cmd, "amx_shutup")) ? "" : "Un-"),againstname,againststeam)

		return PLUGIN_HANDLED
		}
	else if(access(player_id,ADMIN_KICK) && !access(id,ADMIN_IMMUNITY))	//called against an admin by another admin WITHOUT IMMUNITY
		{
		new callname[32], callsteam[32], againstname[32], againststeam[32]
		get_user_name(id,callname,31)
		get_user_authid(id,callsteam,31)
		get_user_name(player_id,againstname,31)
		get_user_authid(player_id,againststeam,31)
		
		//client_print(player_id, print_chat, "* %s has attempted to %sshut you up *",callname,((equal(cmd, "amx_shutup")) ? "" : "un-"))
		
		log_amx("%s<%s> Attempted %sShutup against %s<%s>",callname,callsteam,((equal(cmd, "amx_shutup")) ? "" : "Un-"),againstname,againststeam)

		return PLUGIN_HANDLED
		}
		
	new nameCalled[32], nameAgainst[32]
	new steamCalled[32], steamAgainst[32]
	get_user_name(id, nameCalled, 31)
	get_user_authid(id, steamCalled, 31)
	get_user_name(player_id, nameAgainst, 31)
	get_user_authid(player_id, steamAgainst, 31)

	if(equal(cmd, "amx_shutup"))
		{
		client_print(0,print_chat, "* Nobody wants to hear %s's microphone anymore...", nameAgainst)
		client_cmd(0, "spk scientist/shutup")
		set_speak(player_id, SPEAK_MUTED)
		}
		
	else if(equal(cmd, "amx_unshutup"))
		{
		if(id == player_id)	
			{
			client_print(id, print_chat, "You are not allowed to unshutup yourself!")
	
			return PLUGIN_HANDLED
			}
		else
			{
			client_print(0, print_chat, "* %s is allowed to use their microphone again...", nameAgainst)
			set_speak(player_id, SPEAK_NORMAL)
			}
		}

	// Tell them it succeded
	if(id)
		client_print(id, print_console, "%s was successful",cmd)

	// Now Log it
	log_amx("%s<%s> Called %sShutup against %s<%s>", nameCalled, steamCalled, ((equal(cmd, "amx_shutup")) ? "" : "Un-"), nameAgainst, steamAgainst)

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	Gags ppl
//
public admin_gag(id, level, cid)
{
	if(!cmd_access(id, level, cid, 2))
		return PLUGIN_HANDLED

	new cmd[32], playerName[32]
	read_argv(0, cmd, 31)
	read_argv(1, playerName, 31)

	remove_quotes(playerName)

	// Search for the Player
	new player_id = get_player(playerName)

	if(player_id == -1)
		{
		// Give out error message
		if(id)
			client_print(id, print_console, "Client Not Found!!")

		return PLUGIN_HANDLED
		}

	if(access(player_id,ADMIN_IMMUNITY))	//called AGAINST an admin with IMMUNITY
		{
		new callname[32], callsteam[32], againstname[32], againststeam[32]
		get_user_name(id,callname,31)
		get_user_authid(id,callsteam,31)
		get_user_name(player_id,againstname,31)
		get_user_authid(player_id,againststeam,31)
		
		client_print(player_id, print_chat, "* %s has attempted to %sgag you *",callname,((equal(cmd, "amx_gag")) ? "" : "un-"))
		
		log_amx("%s<%s> Attempted %sGag against %s<%s>",callname,callsteam,((equal(cmd, "amx_gag")) ? "" : "Un-"),againstname,againststeam)

		return PLUGIN_HANDLED
		}
	else if(access(player_id,ADMIN_KICK) && !access(id,ADMIN_IMMUNITY))	//called against an admin by another admin WITHOUT IMMUNITY
		{
		new callname[32], callsteam[32], againstname[32], againststeam[32]
		get_user_name(id,callname,31)
		get_user_authid(id,callsteam,31)
		get_user_name(player_id,againstname,31)
		get_user_authid(player_id,againststeam,31)
		
		//client_print(player_id, print_chat, "* %s has attempted to %sgag you *",callname,((equal(cmd, "amx_gag")) ? "" : "un-"))
		
		log_amx("%s<%s> Attempted %sGag against %s<%s>",callname,callsteam,((equal(cmd, "amx_gag")) ? "" : "Un-"),againstname,againststeam)

		return PLUGIN_HANDLED
		}

	new nameCalled[32], nameAgainst[32]
	new steamCalled[32], steamAgainst[32]
	get_user_name(id, nameCalled, 31)
	get_user_authid(id, steamCalled, 31)
	get_user_name(player_id, nameAgainst, 31)
	get_user_authid(player_id, steamAgainst, 31)

	if(equal(cmd, "amx_gag"))
		{
		client_print(0,print_chat, "* %s is no longer allowed to use the chat or microphone...", nameAgainst)
		client_cmd(0, "spk scientist/shutup2")
		gaged[player_id] = 1
		set_speak(player_id, SPEAK_MUTED)
		}

	else if(equal(cmd, "amx_ungag"))
		{
		if(id == player_id)	
			{
			client_print(id, print_chat, "You are not allowed to ungag yourself!")
	
			return PLUGIN_HANDLED
			}
		else
			{
			client_print(0, print_chat, "* %s is now allowed to use the chat & microphone again...", nameAgainst)
			gaged[player_id] = 0
			set_speak(player_id,SPEAK_NORMAL)
			}
		}

	// Tell them it succeded
	if(id)
		client_print(id, print_console, "%s was successful",cmd)

	// Now Log it
	log_amx("%s<%s> Called %sGag against %s<%s>", nameCalled, steamCalled, ((equal(cmd, "amx_gag")) ? "" : "Un-"), nameAgainst, steamAgainst)

	return PLUGIN_HANDLED
}

////////////////////////////////////////////////////////////////
//	Checks to see if they are gaged
//
public gag_block(id)
{
	if(gaged[id] == 1)
		return PLUGIN_HANDLED

	return PLUGIN_CONTINUE
}

////////////////////////////////////////////////////////////////
// 	Searches for a player
//
get_player(search[])
{
	// See if they are there by exact nick
	new player_id = find_player("ahjl", search)

	// Try to find them by portion of nick
	if(!player_id)
		player_id = find_player("bhjl", search)

	// Try to find them by steam id
	if(!player_id)
		player_id = find_player("chj", search)

	// Try to find them by ip
	if(!player_id)
		player_id = find_player("dhj", search)

	// Try to find them by userid
	if(!player_id)
		player_id = find_player("khj", search)

	if(!player_id)
		return -1

	return player_id
}

////////////////////////////////////////////////////////////////
//	invisibility stock  (fakemeta_util)
//
stock fm_set_entity_visibility(index, visible = 1)
{
	set_pev(index, pev_effects, visible == 1 ? pev(index, pev_effects) & ~EF_NODRAW : pev(index, pev_effects) | EF_NODRAW)

	return 1
}

////////////////////////////////////////////////////////////////
// get weapon name (stock by Wilson)
//
stock get_dod_wpnname( wpnID, szWpnName[32] )
{     
	xmod_get_wpnlogname( wpnID, szWpnName, 31 );
	format( szWpnName, 31, "weapon_%s", szWpnName );
}

////////////////////////////////////////////////////////////////
// Set current clip (not backpack ammo) (stock by Wilson)
//
stock set_clip(id,const weapon[],clip)
{
	new currentent = -1, gunid = 0

	// get origin
	new Float:origin[3];
	entity_get_vector(id,EV_VEC_origin,origin);
	
	while((currentent = find_ent_in_sphere(currentent,origin,Float:1.0)) != 0) {
		new classname[32];
		entity_get_string(currentent,EV_SZ_classname,classname,31);
	
		if(equal(classname,weapon))
			gunid = currentent
	
	}

	set_pdata_int(gunid,108,clip,4); // set their ammo  (115=scoped)
	
	return PLUGIN_CONTINUE
}
